import { getPlaylist,getLists,getDetails,getRank,getsong,getsongInfo } from "../../../api"
import { observable, action, runInAction } from "mobx"

class PlaylistStore {
    @observable Playlist_store = []
    @observable lists_store = []
    @observable details_store = []
    @observable rank_store = []
    @observable player_store = []
    @observable player_song_store =[]
    @action.bound get_playlist() {
        const _this = this
        getPlaylist()
            .then(res => {
                runInAction(function () {
                    _this.Playlist_store = res.playlists

                })
            })
    }
    @action.bound get_lists(){
        const _this = this
        getLists()
            .then(res=>{
                runInAction(function () {
                    _this.lists_store = res.playlists

                })
            })
        
    }
    @action.bound get_details(id){
        const _this = this
        getDetails(id)
        .then(res =>{
            runInAction(function(){
                _this.details_store = res.playlist.tracks
                // console.log(res.playlist.tracks)
            })
        })
    }
    @action.bound get_rank(){
        const _this = this
        getRank()
        .then(res=>{
            runInAction(function(){
                _this.rank_store = res
                console.log(res)
            })
        })
    }
    @action.bound get_music(id){
        const _this = this
        getsong(id)
        .then(res=>{
            runInAction(function(){
                _this.player_store = res.data
            })
        })
    }
    @action.bound get_song(ids){
        const _this = this
        getsongInfo(ids)
        .then(res=>{
            runInAction(function(){
                _this.player_song_store = res.songs
                // console.log(res.songs[0].ar[0].name)
            })
        })
    }
    constructor(root) {
        this.RootStore = root
    }
}
export default PlaylistStore